﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Toolbar.UI
{
    /// <summary>
    /// Interaction logic for ToolbarWindow.xaml
    /// </summary>
    public partial class ToolbarWindow
    {
        public ToolbarWindow()
        {
            InitializeComponent();
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var grid = ((Grid)Content);
            TouchControl(grid, test1);
            TouchControl(grid, test2);
            //test1.
            //grid.f
            //test1.
        }

        private static void TouchControl(Grid grid, ToolBarTray children)
        {
            var orientation = children.Orientation;
            children.Orientation = orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal;
            var index = grid.Children.IndexOf(children);
            grid.BeginInit();
            children.BeginInit();
            grid.Children.Remove(children);
           
            var toolBars = children.ToolBars.ToArray();
            children.ToolBars.Clear();
            foreach (var toolBar in toolBars)
            {
                children.ToolBars.Add(toolBar);
            } 
            grid.Children.Insert(index, children);
            children.InvalidateMeasure();
            children.InvalidateArrange();
            children.InvalidateVisual();
            children.EndInit();
            grid.EndInit();
        }
    }
    public class Manager : DependencyObject
    {


        public Orientation Orientation
        {
            get { return (Orientation)GetValue(OrientationProperty); }
            set { SetValue(OrientationProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Orientation.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty OrientationProperty =
            DependencyProperty.Register("Orientation", typeof(Orientation), typeof(Manager), new UIPropertyMetadata(Orientation.Horizontal));


    }
}
